package com.java.clone.test1;

import java.io.Serializable;
import java.util.HashMap;

public class Context implements Serializable, Cloneable{
	private HashMap<String, Object> userVars = null;
	
	public Context() {
		userVars = new HashMap<String, Object>();
	}
	
	public Context(HashMap<String, Object> userVars){
		this.userVars = userVars;
	}
	
	public void addUserVars(HashMap<String, Object> userVars){
		if(userVars != null){
			this.userVars = userVars;
		}
	}
	
	public HashMap<String, Object> getUserVars() {
		return userVars;
	}
	
	/* 深度复制 */
	public Context clone() {
		Context context = null;
		try {
			context = (Context) super.clone();
			// 只将其指向另外的空间,而不赋值
			HashMap<String, Object> vars = new HashMap<String, Object>();
			this.userVars = vars;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return context;
	}
}	
